<template>
  <div class="app-container">
    <el-form ref="submitParams" :model="submitParams" :rules="rules" label-width="180px" :disabled="isDisabled">
      <el-row v-show="isDisabled">
        <el-col :offset="6" :span="9">
          <el-form-item label="交易流水号" prop="id">
            <el-input v-model="submitParams.id"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="6" :span="9">
          <el-form-item :required="true" label="退回类型" prop="inqType">
            <el-select v-model="submitParams.inqType" clearable placeholder="退回类型" style="width: 100%">
              <el-option
                v-for="dict in dictMap.RETURNTYPECODE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :offset="6" :span="9">
          <el-form-item :required="true" label="原交易流水号/原批次号" prop="oriId">
            <el-input v-model="submitParams.oriId"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-dialog
      title="原交易明细"
      :visible.sync="showDialog"
      center
      width="1024px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="orgTxnForm" :model="orgTxnForm" label-width="110px" :disabled="true">
        <!--交易础信息-->
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>交易基础信息</span>
          </div>
          <el-row>
            <el-col :span="8">
              <el-form-item label="交易流水号" prop="id">
                <el-input v-model="orgTxnForm.id"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="报文标识号" prop="pkgId">
                <el-input v-model="orgTxnForm.pkgId"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="内部机构号" prop="brno">
                <el-input v-model="orgTxnForm.brno"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="工作日期" prop="workdate">
                <!-- <el-input v-model="form.workdate" /> -->
                <el-date-picker
                  v-model="orgTxnForm.workdate"
                  type="date"
                  value-format="yyyyMMdd"
                  placeholder=""
                  style="width: 100%"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="报文类型" prop="pkgNo">
                <el-select style="width: 100%" v-model="orgTxnForm.pkgNo" placeholder="报文类型">
                  <el-option
                    v-for="dict in dictMap.PKG_TYPE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="来往标志" prop="drct">
                <el-select style="width: 100%" v-model="orgTxnForm.drct" placeholder="来往标志">
                  <el-option
                    v-for="dict in dictMap.DRCTCODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="业务类型" prop="bizTypeCode">
                <el-select v-model="orgTxnForm.bizTypeCode" placeholder="业务类型">
                  <el-option
                    v-for="dict in dictMap.BIZ_TYPE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="业务种类" prop="bizCtgyCode" v-if="this.submitParams.inqType==='RP01'">
                <el-select v-model="orgTxnForm.bizCtgyCode" placeholder="业务种类">
                  <el-option
                    v-for="dict in dictMap.BIZ_CTGY"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8" v-if="this.submitParams.inqType==='RP01'">
              <el-form-item label="系统编号" prop="sysCode">
                <el-select v-model="orgTxnForm.sysCode" placeholder="系统编号">
                  <el-option
                    v-for="dict in dictMap.SYS_CODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8" v-if="this.submitParams.inqType==='RP00'">
              <el-form-item label="系统编号" prop="syscode">
                <el-select v-model="orgTxnForm.syscode" placeholder="系统编号">
                  <el-option
                    v-for="dict in dictMap.SYS_CODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="this.submitParams.inqType==='RP01'">
            <el-col :span="8">
              <el-form-item label="包批次号" prop="btId">
                <el-input v-model="orgTxnForm.btId"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="明细条数" prop="dtlNum">
                <el-input v-model="orgTxnForm.dtlNum"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="原明细标识号" prop="oriDtlNo">
                <el-input v-model="orgTxnForm.oriDtlNo"/>
              </el-form-item>
            </el-col>


          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="中心状态" prop="procStatus">
                <el-select v-model="orgTxnForm.procStatus" placeholder="中心状态">
                  <el-option
                    v-for="dict in dictMap.PROCESSSTATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="通讯状态" prop="status">
                <el-select v-model="orgTxnForm.status" placeholder="通讯状态">
                  <el-option
                    v-for="dict in dictMap.PKG_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="8">
              <el-form-item label="交易币种" prop="curcd">
                <el-input v-model="orgTxnForm.curcd" placeholder="人民币-CNY" :disabled="true" style="width: 195px"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="交易金额" prop="amount">
                <ht-amount-input v-model="orgTxnForm.amount" placeholder="交易金额" style="width: 195px"></ht-amount-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="大写金额" prop="bAmount">
                <ht-amount-upper :inputValue="orgTxnForm.amount" placeholder="交易金额"
                                 style="width: 195px"></ht-amount-upper>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row v-if="this.submitParams.inqType==='RP00'">
            <el-col :span="12">
              <el-form-item label="发起参与机构" prop="sender">
                <el-input v-model="orgTxnForm.sender" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="接收参与机构" prop="recver">
                <el-input v-model="orgTxnForm.recver" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="发起清算行行号" prop="directSender">
                <el-input v-model="orgTxnForm.directSender" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="接收清算行行号" prop="directRecver">
                <el-input v-model="orgTxnForm.directRecver" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="this.submitParams.inqType==='RP01'">
            <el-col :span="12">
              <el-form-item label="收款人账号" prop="payeeActno">
                <el-input v-model="orgTxnForm.payeeActno" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="收款人名称" prop="payeeName">
                <el-input v-model="orgTxnForm.payeeName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row v-if="this.submitParams.inqType==='RP01'">
            <el-col :span="12">
              <el-form-item label="付款人账号" prop="payerActno">
                <el-input v-model="orgTxnForm.payeeActno" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="付款人名称" prop="payerName">
                <el-input v-model="orgTxnForm.payeeName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>


        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="submitForm">确认录入</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
    <div slot="footer" class="dialog-footer" align="center">
      <el-button type="primary" @click="searchOrgTxn" v-loading.fullscreen.lock="loading" v-if="showBtn">提 交
      </el-button>
      <el-button type="primary" @click="refresh">重 置</el-button>
    </div>
  </div>
</template>

<script>
import {formBusinessReturnApplyEntry, formBusinessReturnApplyEntrySearchOrgTxn} from "@/api/cnaps/ccms/318";
import {listPageMixin} from "@/libs/listPageMixin";
import HtAmountInput from "@/views/components/HtAmountInput/index.vue";
import fa from "element-ui/src/locale/lang/fa";
import HtAmountUpper from "@/views/components/HtAmountUpper/index.vue";

export default {
  name: "ccmsBusinessReturnEntry",
  mixins: [listPageMixin],
  components: {HtAmountUpper, HtAmountInput},
  data() {
    return {
      // 录入参数
      submitParams: {
        id: undefined,
        inqType: undefined,
        oriId: undefined,
      },
      orgTxnForm: {},
      showDialog: false,
      showBtn: true,
      loading: false,
      isDisabled: false,
      //
      searchFormDictList: ["RETURNTYPECODE",'DRCTCODE','PKG_TYPE','BIZ_TYPE','BIZ_CTGY','PROCESSSTATUS','PKG_STATUS','SYS_CODE'],

      rules: {
        inqType: [{required: true, message: "请输入退回类型", trigger: "blur"}],
        oriId: [
          {required: true, message: "请输入原交易流水号/原批次号", trigger: "blur"},
          {min: 1, max: 45, message: "长度为1-45位", trigger: "blur"},
        ],
      },
    };
  },
  mounted() {
  },
  methods: {
    cancel() {
      this.showDialog = false;
    },
    /** 查询原交易 */
    searchOrgTxn: function () {
      this.$refs["submitParams"].validate((valid) => {
        if (valid) {
          this.loading = true;
          formBusinessReturnApplyEntrySearchOrgTxn(this.submitParams)
            .then((res) => {
              console.log("response", res.result);
              this.orgTxnForm = res.result;
              this.showDialog = true;
              //this.isDisabled = true;
              //this.showBtn = false;
              this.loading = false;
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["submitParams"].validate((valid) => {
        if (valid) {
          this.loading = true;
          formBusinessReturnApplyEntry(this.submitParams)
            .then((res) => {
              this.submitParams.id = res.result.rspId;
              this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
                confirmButtonText: "确定",
                //刷新一下查询列表 TODO
                callback: (action) => {
                },
              });

              this.msgSuccess("录入成功");
              this.showDialog = false;
              this.isDisabled = true;
              this.showBtn = false;
              // this.refresh();
              this.loading = false;
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
    //点击重置按钮
    refresh() {
      this.showBtn = true;
      this.isDisabled = false;
      this.resetForm("submitParams");
    },
  },
};
</script>
